package com.bifrost.repository;

import com.bifrost.entity.Customer;
import com.bifrost.entity.DailySignInHistory;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;

import java.util.Date;
import java.util.List;

/**
 * @author Lee
 * Create Class on 2018/9/5
 * @com.bifrost.repository
 * @wechat-mall
 */
public interface DailySignInHistoryRepository extends JpaRepository<DailySignInHistory,Long>{

    DailySignInHistory findFirstByCustomerOrderBySignInDateDesc(Customer customer);

    @Query(value = "SELECT * FROM daily_sign_in_history D WHERE D.CUSTOMER_ID=?1 AND D.SIGN_IN_DATE>= ?2 ORDER BY D.SIGN_IN_DATE DESC" , nativeQuery = true)
    List<DailySignInHistory> findByCustomerAndMonth(Long customerId, Date firstDayOfMonth);
}
